package cn.dankal.flyaudio.home

import android.view.View
import android.view.ViewGroup
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewAdapter
import cn.dankal.basiclib.base.recyclerview.BaseRecyclerViewHolder
import cn.dankal.basiclib.util.TimeUtil
import cn.dankal.basiclib.util.image.PicUtils
import cn.dankal.business.pojo.InfoBean
import cn.dankal.flyaudio.R
import kotlinx.android.synthetic.main.rv_item_information.view.*
import com.bumptech.glide.Glide
import cn.dankal.flyaudio.R.id.imageView


class InformationAdapter : BaseRecyclerViewAdapter<InfoBean>() {


    override fun getLayoutResId(viewType: Int): Int {
        return R.layout.rv_item_information
    }

    override fun getViewHolder(parent: ViewGroup?, rootView: View?, viewType: Int): BaseRecyclerViewHolder<InfoBean> {
        return InformationViewHolder(rootView)
    }

    override fun onViewRecycled(holder: BaseRecyclerViewHolder<InfoBean>) {
        super.onViewRecycled(holder)
        val imageView = holder.itemView.iv_img
        if (imageView != null) {
            Glide.with(context).clear(imageView)
        }
    }

    class InformationViewHolder(itemView: View?) : BaseRecyclerViewHolder<InfoBean>(itemView) {
        override fun onBindData(data: InfoBean?, position: Int) {
            data?.run {
                PicUtils.loadNormal(cover, itemView.iv_img)
                itemView.tv_title.setText(title)
                itemView.tv_time.setText(TimeUtil.getFgtime(createTime))
                itemView.tv_comment_count.setText(commentNumber)
                itemView.tv_view_count.setText(lookNumber)
            }
        }
    }
}
